//
//  PopPresentationController.swift
//  KKWB
//
//  Created by KSY-iOS on 17/1/9.
//  Copyright © 2017年 KK. All rights reserved.
//

import UIKit

class PopPresentationController: UIPresentationController {

    // MARK:- 懒加载属性
    fileprivate lazy var coverView = UIView()
    
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        
        presentedView?.frame = CGRect(x: 100, y: 60, width: 180, height: 250)
        
        setupCoverView()
    }
}

extension PopPresentationController {
    // 添加蒙板
    fileprivate func setupCoverView() {
        
        containerView?.insertSubview(coverView, at: 0)
        
        coverView.backgroundColor = UIColor(white: 0.8, alpha: 0.4)
        coverView.frame = containerView!.bounds
        
        let tap = UITapGestureRecognizer(target: self, action: #selector(PopPresentationController.coverViewClick))
        coverView .addGestureRecognizer(tap)
    }
}

extension PopPresentationController {
    
    @objc fileprivate func coverViewClick() {
        
        presentedViewController.dismiss(animated: true, completion: nil)
    }
}

